
#include <bits/stdc++.h>
using namespace std;

const int N = 2010;
int n, k;
int a[N][N];

int max_item(int x, int y) {
  int max_i = 0;
  for (int i = x; i <= x + k - 1; i++) {
    for (int j = y; j <= y + k - 1; j++) {
      max_i = max(max_i, a[i][j]);
    }
  }
  return max_i;
}

int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      scanf("%d", &a[i][j]);
  for (int i = 1; i <= n - k + 1; i++) {
    for (int j = 1; j <= n - k + 1; j++) {
      printf("%d ", max_item(i, j));
    }
    cout << endl;
  }

  return 0;
}
